﻿Public Class frmTiposPago 

    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            PanelArriba.Enabled = True
            PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            modificar.Enabled = True
            eliminar.Enabled = True
            imprimir.Enabled = True
            PanelArriba.Enabled = False
            PanelAbajo.Enabled = True

        End If
    End Sub

    Private Sub TipospagoBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles TipospagoBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.TipospagoBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub frmTiposPago_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.tipospago' table. You can move, or remove it, as needed.
        Me.TipospagoTableAdapter.Fill(Me.DbFireAndIceDataSet.tipospago)

    End Sub

    Private Sub agregar_Click(sender As System.Object, e As System.EventArgs) Handles agregar.Click
        BindingNavigatorAddNewItem.PerformClick()
        Mostrar()
    End Sub

    Private Sub modificar_Click(sender As System.Object, e As System.EventArgs) Handles modificar.Click
        Mostrar()
    End Sub

    Private Sub guardar_Click(sender As System.Object, e As System.EventArgs) Handles guardar.Click
        If DescripcionTextBox.Text.Length = 0 Then
            ErrorProvider1.SetError(DescripcionTextBox, "Debe ingresar un nombre para el Tipo de Pago")
        Else
            ErrorProvider1.SetError(DescripcionTextBox, Nothing)

            TipospagoBindingNavigatorSaveItem.PerformClick()
            MessageBox.Show("Se guardó el resgistro satisfactoriamente")
            Mostrar()
        End If
        'Dim a As Integer = TipospagoTableAdapter.ScalarQuerySiHayUnTipoPagoDefaultTrue

        'If a = 1 Then
        'GroupControl1.Enabled = False
        CheckEdit1.Enabled = False
        CheckEdit2.Enabled = False

        'Else
        'GroupControl1.Enabled = True
        'CheckEdit1.Enabled = True
        'CheckEdit2.Enabled = True
        'If CheckEdit1.CheckState = CheckState.Checked = True Then
        '    CheckEdit2.Enabled = False
        'Else
        '    'If CheckEdit2.CheckState = True Then
        '    CheckEdit1.Enabled = False
        '    'End If
        'End If
        'End If

        'If CheckEdit1.CheckState = CheckState.Checked Or CheckEdit2.CheckState = CheckState.Checked Then
        '    ErrorProvider1.SetError(GroupControl1, "Debe ingresar un tipo de pago por Default")
        'Else
        '    ErrorProvider1.SetError(GroupControl1, Nothing)

        'End If
    End Sub

    Private Sub cancelar_Click(sender As System.Object, e As System.EventArgs) Handles cancelar.Click
        ErrorProvider1.SetError(DescripcionTextBox, Nothing)
        Mostrar()
        Me.TipospagoTableAdapter.Fill(Me.DbFireAndIceDataSet.tipospago)
    End Sub

    Private Sub imprimir_Click(sender As System.Object, e As System.EventArgs) Handles imprimir.Click
        GridControl1.ShowPrintPreview()
    End Sub

    Private Sub eliminar_Click(sender As System.Object, e As System.EventArgs) Handles eliminar.Click
        Dim opcion As Integer
        opcion = MsgBox("¿Está seguro que desea eliminar el registro?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Eliminar registro")
        If opcion = vbYes Then
            Try
                TipospagoTableAdapter.DeleteQuery(IdtipopagoTextBox.Text)
                Me.TipospagoTableAdapter.Fill(Me.DbFireAndIceDataSet.tipospago)
            Catch ex As Exception
                MsgBox("Lo sentimos, el registro no puede ser eliminado ya que está relacionado con otras tablas", MsgBoxStyle.Critical, "Error")
            End Try
        End If
    End Sub

    Private Sub ObservacionTextBox_TextChanged(sender As System.Object, e As System.EventArgs) Handles ObservacionTextBox.TextChanged

    End Sub

    Private Sub CheckEdit1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckEdit1.CheckedChanged
        If CheckEdit1.CheckState = CheckState.Checked = True And CheckEdit2.CheckState = CheckState.Unchecked = True Then
            CheckEdit2.Enabled = False
        Else
            'If CheckEdit2.CheckState = True Then
            CheckEdit1.Enabled = False
            'End If
        End If
    End Sub
End Class